package com.liuduidui.sh.controller;

import com.netflix.discovery.DiscoveryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    DiscoveryClient discoveryClient;

    @GetMapping("{id}")
    public Map findUserById(@PathVariable("id") String id) {

        //Ribbon 实现
        String url = "http://user-service/user/" + id;
        // Java发送http请求
        Map userMap = restTemplate.getForObject(url, Map.class);
        // 得到结果
        System.out.println("userMap = " + userMap);
        return userMap;
    }
}